﻿using System.Web.Mvc;
using Abp.Application.Navigation;
using Abp.Configuration.Startup;
using Abp.Runtime.Session;
using Abp.Threading;
using Abp0713Demo.Sessions;
using Abp0713Demo.Web.Models.Layout;

namespace Abp0713Demo.Web.Areas.Admin.Controllers
{
    public class ApplicationController :BaseAdminController
    {
        private readonly IUserNavigationManager _userNavigationManager;
        private readonly ISessionAppService _sessionAppService;
        private readonly IMultiTenancyConfig _multiTenancyConfig;

        public ApplicationController(ISessionAppService sessionAppService, IMultiTenancyConfig multiTenancyConfig, IUserNavigationManager userNavigationManager)
        {
            _sessionAppService = sessionAppService;
            _multiTenancyConfig = multiTenancyConfig;
            _userNavigationManager = userNavigationManager;
        }

        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 默认页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Dashboard()
        {
            return Content("这是工作台内容,暂时空着");
        }

        [ChildActionOnly]
        public PartialViewResult LeftMenu(string activeMenu = "")
        {
            var model = new TopMenuViewModel
            {
                MainMenu = AsyncHelper.RunSync(() => _userNavigationManager.GetMenuAsync(AdminNavigationProvider.MENU_AdminMenu, AbpSession.ToUserIdentifier())),
                ActiveMenuItemName = activeMenu
            };

            return PartialView("_LeftMenu", model);
        }
        [ChildActionOnly]
        public PartialViewResult UserMenuOrLoginLink()
        {
            UserMenuOrLoginLinkViewModel model;

            if (AbpSession.UserId.HasValue)
            {
                model = new UserMenuOrLoginLinkViewModel
                {
                    LoginInformations = AsyncHelper.RunSync(() => _sessionAppService.GetCurrentLoginInformations()),
                    IsMultiTenancyEnabled = _multiTenancyConfig.IsEnabled,
                };
            }
            else
            {
                model = new UserMenuOrLoginLinkViewModel
                {
                    IsMultiTenancyEnabled = _multiTenancyConfig.IsEnabled
                };
            }

            return PartialView("_UserMenuOrLoginLink", model);
        }
    }
}